//
//  ViewController.m
//  02.18Attention
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

//练习
// 1. 分析整个应用中总共有多少哪些对象?罗列出来
// UIApplication对象 [UIApplication sharedApplication]
// AppDelegate对象 [UIApplication sharedApplication].delegate
// UIWindow对象
//AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
//appDelegate.window
// ViewController对象(1个)
// 可见的
// UIView对象(1个)
// UIAlertView类的对象(3个)
// UIActionSheet类的对象(1个)
// UIButto对象(4个)
// UILabel对象(1个)

// 2. 使用Reveal查看程序结构
// 3. 使用纯代码实现本程序







@interface ViewController ()<UIAlertViewDelegate,UIActionSheetDelegate>
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//1.弹出简单提示框
- (IBAction)butPress1 {
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"弹出框信息" message:@"信息~~~~~" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alertView show];
}

//2.弹出多按钮提示框
- (IBAction)butPress2 {
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"错误" message:@"确定关闭吗？" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles: @"不关闭",@"待定",nil];
    [alertView show];
}

//3.弹出带输入框的提示框
- (IBAction)butPress3 {
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"登录" message:@"请输入用户名和密码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: @"取消",nil];
    //    UIAlertViewStyleDefault = 0,            // 默认,即无输入框
    //    UIAlertViewStyleSecureTextInput,        // 密码文本
    //    UIAlertViewStylePlainTextInput,         // 普通文本
    //    UIAlertViewStyleLoginAndPasswordInput   // 用户名密码

    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    [alertView show];
}
//4.弹出操作表
- (IBAction)butPress4 {
    UIActionSheet *sheet =[[UIActionSheet alloc]initWithTitle:@"小明,一起去吃饭吗？" delegate:self cancelButtonTitle:@"我吃过了，你去吧" destructiveButtonTitle:@"一起去吃" otherButtonTitles:@"一起吃KFC",@"一起吃MC" ,nil];
    [sheet showInView:self.view];
}

#pragma mark - UIAlertViewDelegate Method 弹出框的代理方法
// 作为UIAlertView的代理人，控制器类中编写相应的事件处理方法,都是可选方法，根据需求选择适当的实现

// 当用户点了哪个按钮对应的方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"用户点了第几个按钮 = %i,按钮的文字信息:%@",buttonIndex+1,[alertView buttonTitleAtIndex:buttonIndex]);
    NSLog(@"弹窗的信息:%@",alertView.title);
    if ([alertView.title isEqualToString:@"登录"]) {
        NSString *info = [NSString stringWithFormat:@"用户名:%@ 密码:%@",[alertView textFieldAtIndex:0].text,[alertView textFieldAtIndex:1].text];
        self.infoLabel.text = info;
    }
}
// Called when we cancel a view (eg. the user clicks the Home button). This is not called when the user clicks the cancel button.
// If not defined in the delegate, we simulate a click in the cancel button
// 取消的时候
- (void)alertViewCancel:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0, 9_0);
{
    NSLog(@"%s",__FUNCTION__);
}

// 将要弹出的时候
- (void)willPresentAlertView:(UIAlertView *)alertView
{
    NSLog(@"%s",__FUNCTION__);
}

// 已经弹出
- (void)didPresentAlertView:(UIAlertView *)alertView
{
    NSLog(@"%s",__FUNCTION__);
}

// 将要消失
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"%s",__FUNCTION__);
}

// 已经消失
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    NSLog(@"%s",__FUNCTION__);
}

// Called after edits in any of the default fields added by the style
// - (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView NS_DEPRECATED_IOS(2_0, 9_0);

#pragma mark - UIActionSheetDelegate Method 操作表的代理方法

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"操作表的标题是%@",actionSheet.title);
    NSLog(@"用户选择了哪一个按钮:%i,%@",buttonIndex+1,[actionSheet buttonTitleAtIndex:buttonIndex]);
    if(buttonIndex == actionSheet.destructiveButtonIndex)
    {
        NSLog(@"用户点了destructiveBtn");
    }
    else if(buttonIndex == actionSheet.cancelButtonIndex)
    {
        NSLog(@"用户点了cancelBtn");
    }
}








@end
